package team.seekers.hula.course.structure.chapter.entity.dao;

import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import org.springframework.beans.BeanUtils;
import team.seekers.hula.common.entity.BaseDO;
import team.seekers.hula.course.structure.chapter.entity.dto.ChapterManageDTO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 章表(EduChapter)实体类
 *
 * @author GH
 * @since 2022-04-30 18:07:16
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(ChapterDOField.TABLE_NAME)
public class ChapterDO extends BaseDO {

    private static final long serialVersionUID = 1L;

    @TableId(value = ChapterDOField.ID, type = IdType.ASSIGN_ID)
    private String id;

    @TableField(ChapterDOField.NAME)
    private String name;
    /**
     * 所属的课程id
     */
    @TableField(ChapterDOField.CHAPTER_ID)
    private String courseId;
    /**
     * 绑定的富文本课时id
     */
    @TableField(ChapterDOField.SECTION_CONTENT_ID)
    private String sectionContentId;
    /**
     * 章顺序（第几章）
     */
    @TableField(ChapterDOField.SEQUENCE)
    private Integer sequence;

    @TableField(ChapterDOField.DELETED)
    @TableLogic(value = "0", delval = "1")
    private Integer deleted;



    @TableField(value = ChapterDOField.GMT_CREATE, fill = FieldFill.INSERT)
    private Date gmtCreate;

    @TableField(value = ChapterDOField.GMT_MODIFIED, fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;

    public static ChapterDO fromDTO(ChapterManageDTO reqDTO) {
        ChapterDO chapterDO = new ChapterDO();
        BeanUtils.copyProperties(reqDTO,chapterDO);
        return chapterDO;
    }

    public static List<ChapterManageDTO> toDTOs(List<ChapterDO> list) {
        ArrayList<ChapterManageDTO> chapterManageDTOS = new ArrayList<>();
        for (ChapterDO chapterDO : list) {
            ChapterManageDTO chapterManageDTO = new ChapterManageDTO();
            BeanUtils.copyProperties(chapterDO,chapterManageDTO);
            chapterManageDTOS.add(chapterManageDTO);
        }
        return chapterManageDTOS;
    }
}
